/**
 * Created by IntelliJ IDEA.
 * User: user
 * Date: 25.06.12
 * Time: 12:01
 * To change this template use File | Settings | File Templates.
 */
package AS3 {
public class CountryEmissionFactory {

    private var countryXML:XML;

    public function CountryEmissionFactory(countryXML:XML) {
        this.countryXML = countryXML;
    }

    public function createCountryEmission(countryName:String):CountryEmission {
        var emissions:CountryEmission = new CountryEmission();

        emissions.coalTonnePerCO2Tonne = getTonneCoalTonneCO2Ratio(countryName);
        emissions.gasM3PerCO2Tonne = getTonneGasTonneCO2Ratio(countryName);
        emissions.oilTonnePerCO2Tonne = getTonneOilTonneCO2Ratio(countryName);

        emissions.setCO2KWhRatio(getKWhTonneCO2Ratio(countryName) / 365);
        emissions.averageEmission = getEmissionPerCapita(countryName);
        emissions.exportEmission = getEmissionPerCapitaEq(countryName);

        return emissions;
    }

    private function getEmissionPerCapitaEq(country:String):Number {
        return countryXML.Continent.Country.(Name == country).EmissionPerCapitaEq;
    }

    private function getEmissionPerCapita(country:String):Number {
        return countryXML.Continent.Country.(Name == country).EmissionPerCapita;
    }

    private function getKWhTonneCO2Ratio(country:String):Number {
        return countryXML.Continent.Country.(Name == country).CO_kWh;
    }

    private function getTonneCoalTonneCO2Ratio(country:String):Number {
        return countryXML.Continent.Country.(Name == country).CO_Carbon;
    }

    private function getTonneGasTonneCO2Ratio(country:String):Number {
        return countryXML.Continent.Country.(Name == country).CO_Gas;
    }

    private function getTonneOilTonneCO2Ratio(country:String):Number {
        return countryXML.Continent.Country.(Name == country).CO_Oil;
    }
}
}
